<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../assets/test.css">
  <link rel="stylesheet" href="../assets/modal.css">
  <script type="module" src="../assets/modal.js"></script>
  <title>programmatic | Tests</title>
</head>

<body>

  <div>
    <h1 class="h1">Programmatic tests</h1>

    <div class="wrapper">
      <button class="button" id="open-trigger">
        Show modal
      </button>
    </div>

    <div class="wrapper">
      <button class="button" id="open-trigger-2">
        Show modal via element reference
      </button>
    </div>


    <!-- Modal -->


    <div class="modal micromodal-slide" id="modal-1" aria-hidden="true">
      <div class="modal__overlay" tabindex="-1" data-micromodal-close>
        <div class="modal__container" role="dialog" aria-modal="true" aria-labelledby="modal-1-title">
          <header class="modal__header">
            <h2 class="modal__title" id="modal-1-title">
              Micromodal
            </h2>
            <button class="modal__close" aria-label="Close modal" data-micromodal-close></button>
          </header>
          <main class="modal__content" id="modal-1-content">
            <p>
              Hello Modal
            </p>
            <p>
              This is me yo! Lorem ipsum dolor sit amet consectetur adipisicing elit.
            </p>
          </main>
          <footer class="modal__footer">
            <button class="button" id="close-trigger">
              Close modal
            </button>
            <button class="button" id="close-trigger-2">
              Close modal via element reference
            </button>
          </footer>
        </div>
      </div>
    </div>

  </div>

  <script>
    const open = document.getElementById("open-trigger");
    const close = document.getElementById("close-trigger");

    open.addEventListener('click', () => MicroModal.show('modal-1', {
      onShow: () => document.body.classList.add('howdy'),
      onClose: () => document.body.classList.remove('howdy'),
      awaitCloseAnimation: true,
      openClass: 'open'
    }), false);

    close.addEventListener('click', () => MicroModal.close('modal-1'), false);

    const open2 = document.getElementById("open-trigger-2");
    const modal = document.getElementById("modal-1");
    const close2 = document.getElementById("close-trigger-2");

    open2.addEventListener('click', () => MicroModal.show(modal, {
      onShow: () => document.body.classList.add('howdy'),
      onClose: () => document.body.classList.remove('howdy'),
      awaitCloseAnimation: true,
      openClass: 'open'
    }), false);

    close2.addEventListener('click', () => MicroModal.close(modal), false);
  </script>

</body>

</html>
